import Vue from 'vue'
import VueRouter from 'vue-router'

// 解决重复点击导航路由报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

//路由懒加载
const Home = () => import("../views/home/Home");
const Category = () => import("../views/category/Category");
const Cart = () => import("../views/cart/Cart");
const Profile = () => import("../views/profile/Profile");

//没有加载的
// import Home from "../views/home/Home";
// import Category from"../views/category/Category";
// import Cart from "../views/cart/Cart";
// import Profile from "../views/profile/Profile";
//1.安装插件
Vue.use(VueRouter)

//2.创建路由对象定义规则
const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/home",
    component: Home
  },
  {
    path: "/category",
    component: Category
  },
  {
    path: "/cart",
    component: Cart
  },
  {
    path: "/profile",
    component: Profile
  }
];

const router = new VueRouter({
    routes,
    mode:'history'
});

//3.导出路由
export default router;
